package cn.northsea.mapper;

import cn.northsea.pojo.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface PurchaseMapper {
    List<PurchaseVO> like(@Param("purchaseOrder") String purchaseOrder, @Param("start") String start, @Param("end") String end);

    @Update("update erp_supply_order set status=1 where purchase_id=#{value}")
    void statusPur(Integer id);


    List<PurchaseTwoVO> findPurchase(@Param("purchaseOrder") String purchaseOrder, @Param("start") String start, @Param("end") String end);

    @Select("select * from erp_suppliers")
    List<Supplier> findSupplier();

    @Select("select * from erp_suppliers where supplier_name=#{value}")
    Supplier findName(String supplierName);

    @Select("select * from erp_material")
    List<Material> findMaterials();

    @Select("select * from erp_material where material_id=#{value}")
    Material getPrice(Integer materialId);

    @Select("select * from erp_user")
    List<User> findUser();

    @Insert("insert into erp_supply_order values (null,#{supplierId},#{quantity},0,#{total},#{str},#{userId},#{time},#{materialId})")
    void addPurchase(@Param("supplierId") Integer supplierId, @Param("str") String str, @Param("quantity") Integer quantity, @Param("total") Double total, @Param("userId") Integer userId, @Param("time") Date time, @Param("materialId") Integer materialId);

    @Select("select * from erp_material where material_id=#{value}")
    Material findMaterialsById(Integer materialId);

    @Select("select * from erp_supply_order where purchase_id=#{value}")
    ErpSupplyOrder findpurchaseIdById(Integer purchaseId);

    @Insert("insert into purchase_order_items values (null,#{purchaseId},#{materialId},#{purchaseQuantity},#{materialPrice},#{total},#{purchaseOrder},#{orderDate})")
    void addCaiGou(@Param("purchaseId") Integer purchaseId, @Param("materialId") Integer materialId, @Param("purchaseQuantity") Integer purchaseQuantity, @Param("materialPrice") Double materialPrice, @Param("total") Double total, @Param("purchaseOrder") String purchaseOrder, @Param("orderDate") Date orderDate);

    @Select("select * from purchase_order_items where purchase_order=#{value}")
    String getPurchaseOrder(String purchaseOrder);

    @Delete("delete from erp_supply_order where purchase_id=#{value}")
    void delPurchase(Integer purchaseId);

    @Delete("delete from purchase_order_items where purchase_order_id=#{value}")
    void delOrderItems(Integer purchaseId);

    @Select("select * from erp_user where user_id=#{value}")
    User findUserById(Integer userId);

    @Update("update erp_supply_order set suppliers_id=#{supplierId},purchase_quantity=#{quantity},user_id=#{userId},material_id=#{materialId} where purchase_id=#{purchaseId} ")
    void updatePurchase(@Param("purchaseId") Integer purchaseId, @Param("supplierId") Integer supplierId, @Param("materialId") Integer materialId, @Param("quantity") Integer quantity, @Param("userId") Integer userId);
//   @Insert("insert into purchase_order_items values (null,#{supplierId},null,#{materialId},#{quantity},#{unitPrice},#{price},#{date})")
//    void addPurchase(@Param("supplierId")Integer supplierId, @Param("supplierId")Integer materialId, @Param("supplierId")Integer quantity, @Param("supplierId")Integer unitPrice,@Param("supplierId")Integer price,@Param("supplierId")Date date);
}
